package com.admin.dao;

import com.admin.bean.Discuss;
import com.admin.bean.Order;
import com.admin.util.JDBCUtils;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.Statement;
import java.util.ArrayList;
import java.util.List;

public class discussDao {
    public List<Discuss> selectFlight(String time) {
        List<Discuss> discusses=new ArrayList<Discuss>();
        try{
            Connection connection = JDBCUtils.getConnection();
            String sql ="select *from `discuss` where time like ?";
            PreparedStatement ps=connection.prepareStatement(sql);
            ps.setString(1,time+"%");
            ResultSet resultSet=ps.executeQuery();
            System.out.println(ps);
            while (resultSet.next()){
                Discuss discuss=new Discuss();
                discuss.setId(resultSet.getInt(1));
                discuss.setTime(resultSet.getString(2));
                discuss.setUserName(resultSet.getString(3));
                discuss.setMessage(resultSet.getString(4));
                discusses.add(discuss);
            }
        }catch (Exception e){
            e.printStackTrace();
        }
        return discusses;
    }

    public void deleteDiscuss(String id) {
        try {
            Connection connection= JDBCUtils.getConnection();
            String sql="delete from `discuss` where id in ("+id+")";
            Statement st=connection.createStatement();
            st.executeUpdate(sql);
        }catch (Exception e)
        {
            e.printStackTrace();
        }
    }
}
